package repository

import (
	"context"
	"webook/internal/repository/cache"
)

var (
	ErrCodeSendTooMany   = cache.ErrCodeSendTooMany
	ErrCodeVerifyTooMany = cache.ErrCodeVerifyTooMany
)

type CodeRepository interface {
	Store(ctx context.Context, key string, value string) error
	Verify(ctx context.Context, key string, value string) (bool, error)
}

type CacheCodeRepository struct {
	cache cache.CodeCache
}

func NewCodeRepository(c cache.CodeCache) CodeRepository {
	return &CacheCodeRepository{
		cache: c,
	}
}

func (repo *CacheCodeRepository) Store(ctx context.Context, key string, value string) error {
	return repo.cache.Set(ctx, key, value)
}

func (repo *CacheCodeRepository) Verify(ctx context.Context, key string, value string) (bool, error) {
	return repo.cache.Verify(ctx, key, value)
}
